package app.netant.book.xiami77;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class Xiami77Detail extends BaseDetail {

	public Xiami77Detail(String netSite) {
		super(netSite);
		this.preHref = "https://www.xiami77.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("#navbot #pageMain #mainBody .pageMainArea .downInfoTitle h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int st = title.indexOf("《");
			int ed = title.indexOf("》");
			if(st>=0 && ed>=0 && ed>st){
				title = title.substring(st+1,ed);
			}
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("#navbot #pageMain #mainBody .pageMainArea #downInfoArea table tbody tr td dd.downInfoRowR");
		if(parts.size()>0){
			String tags = parts.get(0).text();
			this.splitTags(tags, true);
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("#navbot #pageMain #mainBody .pageMainArea .mainstory .story #mainSoftIntro");
		if(parts.size()>0){
			String memo = this.getString(parts.get(0).text());
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("#navbot #pageMain #mainBody .pageMainArea .mainstory .story #downAddress a");
		if(parts.size()>0){
			String click = parts.get(0).attr("onclick");
			int st = click.indexOf("https://");
			int ed = click.indexOf("','',");
			if(st>0 && ed>0 && ed>st){
				String href = click.substring(st,ed);
				Xiami77Detail detail = new Xiami77Detail(href);
				String url = detail.stepHref();
				System.out.println("【Href】:"+url);
				this.entity.setDownPath(url);
			}
		}
	}
	
	public String stepHref(){
		Elements parts = this.select("table tbody tr td[align='center'] a");
		if(parts.size()>0){
			String href = parts.attr("href");
			if(href.startsWith("..")){
				href = "https://www.xiami77.com/e/DownSys" + href.substring(2);
				return href;
			}
		}
		return null;
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("#navbot #pageMain .crumb .crumbleft a");
		if(parts.size()>1){
			String type = parts.get(1).text().trim();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		Xiami77Detail detail = new Xiami77Detail("https://www.xiami77.com/yq/23786.html#ecms");
		detail.test();
	}



}
